(deftemplate dama
    (slot nume(allowed-values a b c d))
    (slot x)
    (slot y)
 )
(foreach ?nd (create$ a b c d)
(foreach ?i (create$ 1 2 3 4)
(foreach ?j (create$ 1 2 3 4)
     (assert(dama (nume ?nd)(x ?i)(y ?j))))))

(defrule rezolvare
   ?f1 <- (dama(nume a)(x ?x1)(y ?y1))
   ?f2 <-(dama(nume b)(x ?x2)(y ?y2))
   ?f3 <- (dama(nume c)(x ?x3)(y ?y3))
   ?f4 <-(dama(nume d)(x ?x4)(y ?y4))
    
    (test(and (neq ?x1 ?x2)(neq ?x1 ?x3)(neq ?x1 ?x4)))
    (test(and (neq ?x2 ?x3)(neq ?x2 ?x4)))
    (test(neq ?x3 ?x4))
    
    (test(and (neq ?y1 ?y2)(neq ?y1 ?y3)(neq ?y1 ?y4)))
    (test(and (neq ?y2 ?y3)(neq ?y2 ?y4)))
    (test(neq ?y3 ?y4))
    
     (test(and(neq(- ?x1 ?y1)(- ?x2 ?y2))
              (neq(- ?x1 ?y1)(- ?x3 ?y3))
              (neq(- ?x1 ?y1)(- ?x4 ?y4))
              (neq(- ?x2 ?y2)(- ?x3 ?y3))
              (neq(- ?x2 ?y2)(- ?x4 ?y4))
              (neq(- ?x3 ?y3)(- ?x4 ?y4))
      ))
    
    
      (test(and(neq(+ ?x1 ?y1)(+ ?x2 ?y2))
              (neq(+ ?x1 ?y1)(+ ?x3 ?y3))
              (neq(+ ?x1 ?y1)(+ ?x4 ?y4))
              (neq(+ ?x2 ?y2)(+ ?x3 ?y3))
              (neq(+ ?x2 ?y2)(+ ?x4 ?y4))
              (neq(+ ?x3 ?y3)(+ ?x4 ?y4))
      ))
        
    =>
    (printout t "************Solutia*******************" crlf)
    (printout t "Dama1 se afla pe pozitia: " ?x1 " " ?y1 crlf)
    (printout t "Dama2 se afla pe pozitia: " ?x2 " " ?y2 crlf)
    (printout t "Dama3 se afla pe pozitia: " ?x3 " " ?y3 crlf)
    (printout t "Dama4 se afla pe pozitia: " ?x4 " " ?y4 crlf)
    
    
     (retract ?f1)
     (retract ?f2)
     (retract ?f3)
     (retract ?f4) ;; nu mai avem 64 ci 32???
    
    )
(run)
(facts)

